package com.itcast.demo_one.kotlin


fun demo01(){
    val numbers = listOf(1,2,3,4,5)

    // 1.过滤出大于3的数字
    //var newList = numbers.filter({item -> item > 3})
    // 简写，参数只有一个用it代替
    val newList = numbers.filter{it > 3}
    println(newList)

    // 2.映射数字的平方
    val newList2 = numbers.map{it * it}
    println(newList2)

    // 查找 - 第一个大于3的数字
    val first = numbers.first{it > 3}
    println(first)

    // 3.查找 - 是否有数字大于3
    val any = numbers.any{it > 3}
    println(any)
}


fun demo02(){
    fun calc(a:Int,b:Int,op:(Int,Int)->Int): Int {
        return op(a, b)
    }

//    val res1 = calc(6,10,{a,b -> a + b})
    // 简写
    val res1 = calc(6,10) {a,b -> a + b}
    println(res1)

    val res2 = calc(6,10,{a,b -> a - b})
    println(res2)

    val res3 = calc(6,10,{a,b -> a * b})
    println(res3)
}
fun main (){
//    demo01()
    demo02()
}